﻿namespace NoIdeaIoc;
/// <summary>
/// 迷你Ioc接口
/// </summary>
public interface ILifeTime : IServiceProvider, IDisposable, ISupportRequiredService, IAsyncDisposable
{
    /// <summary>
    /// 获取计时器
    /// </summary>
    Stopwatch Stopwatch { get; }
    /// <summary>
    /// 请求Id
    /// </summary>
    Guid SessionId { get; }
    /// <summary>
    /// 根据命名键获得接口实例
    /// <para>需要初始化Http的请继承IHttpContextInit接口</para>
    /// <para>已经初始化Http</para>
    /// </summary>
    /// <param name="serviceType"></param>
    /// <param name="keyName">命名键(自动转换为小写)</param>
    /// <returns></returns>
    object? Resolve(Type serviceType, string keyName);
    /// <summary>
    /// 获取实例
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    T? Resolve<T>();
    /// <summary>
    /// 获取命名实例
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    T? Resolve<T>(string keyName);
    /// <summary>
    /// 创建并绑定到生命周期
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    T Create<T>() where T : new();
    /// <summary>
    /// 将新对象注册为系统单例
    /// <para>可被容器获取</para>
    /// </summary>
    /// <param name="instance"></param>
    void RegisterSingleton(object instance);
    /// <summary>
    /// 将新对象注册为本生命周期服务
    /// <para>可被容器获取</para>
    /// </summary>
    /// <param name="instance"></param>
    void RegisterService(object instance);
    /// <summary>
    /// 注册可释放实例
    /// <para>不会被获取</para>
    /// </summary>
    /// <param name="dispose"></param>
    void RegisterForDispose(object dispose);
}